package com.junmeng.jdemo.itemdecoration;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.common.base.BaseActivityDelegate;
import com.example.common.recycler.viewbinding.BaseSingleViewBindingRecyclerAdapter;
import com.example.common.recycler.viewbinding.ViewBindingViewHolder;
import com.junmeng.jdemo.R;
import com.junmeng.jdemo.databinding.ActivityItemDecorationBinding;
import com.junmeng.jdemo.databinding.ItemSimpleDecorationBinding;

import java.util.List;

public class ItemDecorationActivity extends BaseActivityDelegate {

    ActivityItemDecorationBinding binding;
    MyAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityItemDecorationBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initRecyclerView();
        initData();
    }

    private void initData() {
        adapter.addItem(new ItemData());
        adapter.addItem(new ItemData());
        adapter.addItem(new ItemData());
        adapter.addItem(new ItemData());
        adapter.addItem(new ItemData());
    }

    void initRecyclerView() {
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(this));

        //BaseLayoutOrderItemDecoration可以看到并不会被覆盖，而是按照顺序依次绘制
        binding.recyclerView.addItemDecoration(new OrderItemDecorationEnd());
        binding.recyclerView.addItemDecoration(new OrderItemDecorationStart());
        binding.recyclerView.addItemDecoration(new OrderItemDecorationTop());
        binding.recyclerView.addItemDecoration(new OrderItemDecorationBottom());

        binding.recyclerView.addItemDecoration(new OrderItemDecorationTop());
        binding.recyclerView.addItemDecoration(new OrderItemDecorationBottom());
        binding.recyclerView.addItemDecoration(new OrderItemDecorationStart());
        binding.recyclerView.addItemDecoration(new OrderItemDecorationEnd());

        DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, RecyclerView.VERTICAL);//两个DividerItemDecoration的话可以看到会覆盖
        dividerItemDecoration.setDrawable(getDrawable(R.drawable.shape_item_decoration_inset));
//        dividerItemDecoration.setDrawable(getDrawable(R.drawable.shape_item_decoration));
        binding.recyclerView.addItemDecoration(dividerItemDecoration);
        binding.recyclerView.setAdapter(adapter = new MyAdapter());
    }


    class MyAdapter extends BaseSingleViewBindingRecyclerAdapter<ItemData, ItemSimpleDecorationBinding> {

//        @Override
//        public int getItemLayoutResId() {
//            return R.layout.item_simple_decoration;
//        }

        @Override
        public void onBindView(@NonNull ViewBindingViewHolder<ItemSimpleDecorationBinding> holder, int position, ItemData itemData, @NonNull List<Object> payloads) {
            holder.binding.text.setText("i am ItemView");
        }
    }

    class ItemData {

    }
}